#!/usr/bin/python
# -*- coding: UTF-8 -*-

import pymysql

# 打开数据库连接
db = pymysql.connect(host='127.0.0.1',
                             user='root',
                             password='tc123456',
                             database='cgw',
                             cursorclass=pymysql.cursors.DictCursor)

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
sql = "select distinct OBJECTID as OBJECTID from arrangement "
# 使用 execute()  方法执行 SQL 查询
cursor.execute(sql)
# 使用 fetchone() 方法获取单条数据.
rows = cursor.fetchall()

OBJECTIDS="in ("

i=0

for row in rows:
	OBJECTIDS += ",'"+row["OBJECTID"]+"'"
	i=i+1

print(i)
print(OBJECTIDS+")")


db.close()

